exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseController {
    __before() {//前置操作，在action执行，返回false则终止当前控制器
    }

    getOrgByRoleAction() {
        var _this = this;

        return _asyncToGenerator(function* () {
            //分页查询角色信息
            let aj = think.ajaxJson();
            const data = { orgids: _this.get('auth_org_ids').split(',') };
            const roleService = _this.service('sys/RoleService');
            const res = yield roleService.getOrgByRole(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = "获取部门列表失败";
            }
            return _this.json(aj);
        })();
    }

    getRoleListAction() {
        var _this2 = this;

        return _asyncToGenerator(function* () {
            //分页查询角色信息
            let aj = think.ajaxJson();
            const data = _this2.get('page,pageSize,rolename');
            const roleService = _this2.service('sys/RoleService');
            const res = yield roleService.getRoleList(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = "角色列表查询错误";
            }
            return _this2.json(aj);
        })();
    }

    delRoleInfoAction() {
        var _this3 = this;

        return _asyncToGenerator(function* () {
            //删除角色信息
            let aj = think.ajaxJson();
            const data1 = { id: _this3.post('id') };
            // const data2 = {
            //     del_flag:1,
            //     update_by:this.post('update_by'),
            //     update_date:new Date()
            // };
            const roleService = _this3.service('sys/RoleService');
            const res = yield roleService.delSysRoleInfo(data1);
            if (res && res.error) {
                aj.success = false;
                aj.msg = "角色信息删除错误";
            }
            if (res && res.msg) {
                aj.success = false;
                aj.msg = res.msg;
            }
            return _this3.json(aj);
        })();
    }

    getRoleNamesAction() {
        var _this4 = this;

        return _asyncToGenerator(function* () {
            //查询角色名称
            let aj = think.ajaxJson();
            const roleService = _this4.service('sys/RoleService');
            const res = yield roleService.getRoleNames();
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = "角色名称查询错误";
            }
            return _this4.json(aj);
        })();
    }

    saveRoleInfoAction() {
        var _this5 = this;

        return _asyncToGenerator(function* () {
            //保存角色信息
            let aj = think.ajaxJson();
            let data = _this5.post('rolename,description,enname,rolecode,useable,is_sys,data_scope,update_by,remarks,auth_org_ids');
            data.update_date = new Date();
            if (_this5.post('id')) {
                data.id = _this5.post('id');
            } else {
                data.create_by = data.update_by;
                data.create_date = new Date();
            }
            const roleService = _this5.service('sys/RoleService');
            const res = yield roleService.saveRoleInfo(data);
            if (res && res.error) {
                aj.success = false;
                aj.msg = "角色信息保存错误";
            }
            if (!res) {
                aj.success = false;
                aj.msg = "角色名称或角色编码已存在，请确认后重新输入";
            }
            return _this5.json(aj);
        })();
    }

    /********************角色用户 start*************************** */

    getRoleByUserAction() {
        var _this6 = this;

        return _asyncToGenerator(function* () {
            //根据用户id获取角色列表
            let aj = think.ajaxJson();
            const data = { userid: _this6.get('userid') };
            const roleService = _this6.service('sys/RoleService');
            const res = yield roleService.getRoleByUser(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = "用户角色列表查询错误";
            }
            return _this6.json(aj);
        })();
    }
    delUserRoleAction() {
        var _this7 = this;

        return _asyncToGenerator(function* () {
            //用户与当前角色解除绑定
            let aj = think.ajaxJson();
            const postData = _this7.post('roleid,userid');
            const roleService = think.service('sys/RoleService');
            const res = yield roleService.delUserRole(postData);
            if (res && res.error) {
                aj.success = false;
                aj.msg = "用户角色解绑错误";
            }
            return _this7.json(aj);
        })();
    }

    getUsersByRoleAction() {
        var _this8 = this;

        return _asyncToGenerator(function* () {
            //获取该角色绑定的所有用户
            let aj = think.ajaxJson();
            const data = _this8.get('page,pageSize,options,roleid');
            const roleService = think.service('sys/RoleService');
            const res = yield roleService.getUsersByRole(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = "角色绑定的用户列表查询错误";
            }
            return _this8.json(aj);
        })();
    }

    getUsersNotBindAction() {
        var _this9 = this;

        return _asyncToGenerator(function* () {
            //获取未绑定该角色的用户
            let aj = think.ajaxJson();
            const getData = _this9.get('page,pageSize,options,roleid');
            const roleService = think.service('sys/RoleService');
            const res = yield roleService.getUsersNotBindRole(getData);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = "未绑定角色的用户列表查询错误";
            }
            return _this9.json(aj);
        })();
    }

    saveUserRoleAction() {
        var _this10 = this;

        return _asyncToGenerator(function* () {
            //保存用户角色绑定
            let aj = think.ajaxJson();
            const data = _this10.post('roleid,userList');
            const roleService = think.service('sys/RoleService');
            const res = yield roleService.saveUserRole(data);
            if (res && res.error) {
                aj.success = false;
                aj.msg = "用户角色绑定错误";
            }
            return _this10.json(aj);
        })();
    }
    delUserInfoAction() {
        var _this11 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const data = { id: _this11.post('id') };
            const userService = think.service('sys/UserService');
            const res = yield userService.delUserInfo(data);
            if (res && res.error) {
                aj.success = false;
                aj.msg = "用户信息删除错误";
            }
            if (!res) {
                aj.success = false;
                aj.msg = "系统用户不可删除";
            }
            return _this11.json(aj);
        })();
    }
    /***********************角色用户 end************************************* */

    /*********************角色菜单相关 begin************************* */
    getAllMenuAction() {
        var _this12 = this;

        return _asyncToGenerator(function* () {
            //获取所有菜单
            let aj = think.ajaxJson();
            const roleService = think.service('sys/RoleService');
            const res = yield roleService.getAllMenu();
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = "获取菜单列表错误";
            }
            return _this12.json(aj);
        })();
    }
    getRoleMenuAction() {
        var _this13 = this;

        return _asyncToGenerator(function* () {
            //根据角色获取菜单权限
            let aj = think.ajaxJson();
            const data = { roleid: _this13.get('roleid') };
            const roleService = think.service('sys/RoleService');
            const res = yield roleService.getRoleMenu(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = "获取角色权限错误";
            }
            return _this13.json(aj);
        })();
    }

    saveRoleMenuAction() {
        var _this14 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const data = _this14.post('roleid,delList,addList');
            const roleService = think.service('sys/RoleService');
            const res = yield roleService.saveRoleMenu(data);
            if (res && res.error) {
                aj.success = false;
                aj.msg = "保存角色权限关联错误";
            }
            return _this14.json(aj);
        })();
    }

    getUserRoleMenuAction() {
        var _this15 = this;

        return _asyncToGenerator(function* () {
            //根据用户角色获取绑定的全部菜单列表
            let aj = think.ajaxJson();
            const roleList = _this15.post('roleList');
            const roleService = think.service('sys/RoleService');
            const res = yield roleService.getUserRoleMenu(roleList);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = "菜单列表查询错误";
            }
            return _this15.json(aj);
        })();
    }
    /**************************角色菜单相关 end******************************** */
    __after() {//后置操作,在action调用之后执行

    }

    __call() {//魔术函数

    }
};